package com.ruyuan.o2o.groupbuy.common.log;

import org.apache.logging.log4j.util.Strings;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 提供给日志过滤器使用，在日志中增加hostname和ip
 *
 * @author ming qian
 */
public class HostInfoClient {
    private static String hostname;
    private static String ip;

    public static String getHostName() {
        if (Strings.isBlank(hostname)) {
            try {
                hostname = InetAddress.getLocalHost().getHostName();
            } catch (UnknownHostException e) {
                hostname = null;
            }
        }
        return hostname;
    }

    public static String getIp() {
        if (Strings.isBlank(ip)) {
            try {
                ip = InetAddress.getLocalHost().getHostAddress();
            } catch (UnknownHostException e) {
                ip = null;
            }
        }
        return ip;
    }
}
